﻿#region Copyright 2008 - Evolution Systems.
//
// Author: José Rogério Ferreira dos Santos(joserogerio.santos@gmail.com)
// Date: 27/05/2009
// Time: 19:30
// All rights are reserved. Reproduction or transmission in whole or in part, in
// any form or by any means, eletronic, mechanical or otherwise, is prohibited
// without the prior written permission of the author.
//
// Filename: ${FILE_NAME}.cs
#endregion
using System;
using System.Collections.Generic;

namespace csharp.rad.finan
{
	/// <summary>
	/// Description of BprDetail.
	/// </summary>
	public class BprDetail : common.DefaultClass, common.IClass
	{
		#region private declarations
			private string _number;
			private string _document_number;
			private string _bank_number;
			private string _create_date;
			private string _create_time;
			private string _emission_date;
			private string _expiration_date;
			private string _payment_date;
			private string _value;
			private string _juros_value;
			private string _increment_value;
			private string _discount_value;
			private string _penalty_value;
			private string _perc_juros;
			private string _perc_discount;
			private string _perc_penalty;
			private string _penalty_after_days;
			private string _discount_until;
			private string _check;
			private string _ticket_printed;
			private string _ticket_emission_date;
			private string _historic;
			private string _obs;
			private string _bpr_id;
			private string _status_id;
			private string _document_type_id;
			private string _user_id;
			private string _bank_id;
			private string _agreement_id;
			private string _collection_type_id;
			private string _check_id;
			private string _paid_value;		
		#endregion
		
		#region properties
		public string number 
		{
			get { return _number; }
			set { _number = value; }
		}
		
		public string documentNumber 
		{
			get { return _document_number; }
			set { _document_number = value; }
		}
		
		public string bankNumber 
		{
			get { return _bank_number; }
			set { _bank_number = value; }
		}
		
		public string createDate 
		{
			get { return _create_date; }
			set { _create_date = value; }
		}
		
		public string createTime 
		{
			get { return _create_time; }
			set { _create_time = value; }
		}
		
		public string emissionDate 
		{
			get { return _emission_date; }
			set { _emission_date = value; }
		}
		
		public string expirationDate 
		{
			get { return _expiration_date; }
			set { _expiration_date = value; }
		}
		
		public string paymentDate 
		{
			get { return _payment_date; }
			set { _payment_date = value; }
		}
		
		public string value 
		{
			get { return _value; }
			set { _value = value; }
		}
		
		public string jurosValue 
		{
			get { return _juros_value; }
			set { _juros_value = value; }
		}
		
		public string incrementValue 
		{
			get { return _increment_value; }
			set { _increment_value = value; }
		}
		
		public string discountValue 
		{
			get { return _discount_value; }
			set { _discount_value = value; }
		}
		
		public string penaltyValue 
		{
			get { return _penalty_value; }
			set { _penalty_value = value; }
		}
		
		public string percJuros 
		{
			get { return _perc_juros; }
			set { _perc_juros = value; }
		}
		
		public string percDiscount 
		{
			get { return _perc_discount; }
			set { _perc_discount = value; }
		}
		
		public string percPenalty 
		{
			get { return _perc_penalty; }
			set { _perc_penalty = value; }
		}
		
		public string penaltyAfterDays 
		{
			get { return _penalty_after_days; }
			set { _penalty_after_days = value; }
		}
		
		public string discountUntil 
		{
			get { return _discount_until; }
			set { _discount_until = value; }
		}
		
		public string check 
		{
			get { return _check; }
			set { _check = value; }
		}
		
		public string ticketPrinted 
		{
			get { return _ticket_printed; }
			set { _ticket_printed = value; }
		}
		
		public string ticketEmissionDate 
		{
			get { return _ticket_emission_date; }
			set { _ticket_emission_date = value; }
		}
		
		public string historic 
		{
			get { return _historic; }
			set { _historic = value; }
		}
		
		public string obs 
		{
			get { return _obs; }
			set { _obs = value; }
		}
		
		public string bprId 
		{
			get { return _bpr_id; }
			set { _bpr_id = value; }
		}
		
		public string statusId 
		{
			get { return _status_id; }
			set { _status_id = value; }
		}
		
		public string documentTypeId 
		{
			get { return _document_type_id; }
			set { _document_type_id = value; }
		}
		
		public string userId 
		{
			get { return _user_id; }
			set { _user_id = value; }
		}
		
		public string bankId 
		{
			get { return _bank_id; }
			set { _bank_id = value; }
		}
		
		public string agreementId 
		{
			get { return _agreement_id; }
			set { _agreement_id = value; }
		}
		
		public string collectionTypeId {
			get { return _collection_type_id; }
			set { _collection_type_id = value; }
		}
		
		public string checkId 
		{
			get { return _check_id; }
			set { _check_id = value; }
		}
		
		public string paidValue 
		{
			get { return _paid_value; }
			set { _paid_value = value; }
		}
			
		#endregion
		
		public BprDetail()
		{
			gsql.table = "finan.bpr_detail";
			_sequence  = "finan.bpr_detail_bpr_detail_id_seq";        
		}
		
		public void clear()
		{
			_id 						= string.Empty;
			_number 					= string.Empty;
			_document_number 			= string.Empty;
			_bank_number 				= string.Empty;
			_create_date 				= string.Empty;
			_create_time 				= string.Empty;
			_emission_date 				= string.Empty;
			_expiration_date 			= string.Empty;
			_payment_date 				= string.Empty;
			_value 						= string.Empty;
			_juros_value 				= string.Empty;
			_increment_value 			= string.Empty;
			_discount_value 			= string.Empty;
			_penalty_value 				= string.Empty;
			_perc_juros 				= string.Empty;
			_perc_discount 				= string.Empty;
			_perc_penalty 				= string.Empty;
			_penalty_after_days 		= string.Empty;
			_discount_until 			= string.Empty;
			_check 						= string.Empty;
			_ticket_printed 			= string.Empty;
			_ticket_emission_date 		= string.Empty;
			_historic 					= string.Empty;
			_obs 						= string.Empty;
			_bpr_id 					= string.Empty;
			_status_id	 				= string.Empty;
			_document_type_id		 	= string.Empty;
			_user_id 					= string.Empty;
			_bank_id 					= string.Empty;
			_agreement_id 				= string.Empty;
			_collection_type_id 		= string.Empty;
			_check_id 					= string.Empty;
			_paid_value 				= string.Empty;          			
		}
		
		public override void get(System.Data.DataRow dr)
		{
			_id 							= dr["bpr_detail_id"].ToString();
			_number 						= dr["bpr_detail_number"].ToString();
			_document_number 				= dr["bpr_detail_document_number"].ToString();
			_bank_number 					= dr["bpr_detail_bank_number"].ToString();
			_create_date 					= dr["bpr_detail_create_date"].ToString();
			_create_time 					= dr["bpr_detail_create_time"].ToString();
			_emission_date 					= dr["bpr_detail_emission_date"].ToString();
			_expiration_date 				= dr["bpr_detail_expiration_date"].ToString();
			_payment_date 					= dr["bpr_detail_payment_date"].ToString();
			_value 							= dr["bpr_detail_value"].ToString();
			_juros_value 					= dr["bpr_detail_juros_value"].ToString();
			_increment_value 				= dr["bpr_detail_increment_value"].ToString();
			_discount_value 				= dr["bpr_detail_discount_value"].ToString();
			_penalty_value 					= dr["bpr_detail_penalty_value"].ToString();
			_perc_juros 					= dr["bpr_detail_perc_juros"].ToString();
			_perc_discount 					= dr["bpr_detail_perc_discount"].ToString();
			_perc_penalty 					= dr["bpr_detail_perc_penalty"].ToString();
			_penalty_after_days 			= dr["bpr_detail_penalty_after_days"].ToString();
			_discount_until 				= dr["bpr_detail_discount_until"].ToString();
			_check 			 				= dr["bpr_detail_check"].ToString();
			_ticket_printed 				= dr["bpr_detail_ticket_printed"].ToString();
			_ticket_emission_date 			= dr["bpr_detail_ticket_emission_date"].ToString();
			_historic 						= dr["bpr_detail_historic"].ToString();
			_obs 							= dr["bpr_detail_obs"].ToString();
			_bpr_id			 				= dr["bpr_detail_bpr_id"].ToString();
			_status_id 						= dr["bpr_detail_status_id"].ToString();
			_document_type_id 				= dr["bpr_detail_document_type_id"].ToString();
			_user_id 						= dr["bpr_detail_user_id"].ToString();
			_bank_id 						= dr["bpr_detail_bank_id"].ToString();
			_agreement_id 					= dr["bpr_detail_agreement_id"].ToString();
			_collection_type_id 			= dr["bpr_detail_collection_type_id"].ToString();
			_check_id 						= dr["bpr_detail_check_id"].ToString();
			_paid_value           			= dr["bpr_detail_paid_value"].ToString();        
		}
		
		public override void setGsql()
		{
			gsql.setValue(_id 							,"bpr_detail_id");
			gsql.setValue(_number 						,"bpr_detail_number");
			gsql.setValue(_document_number 				,"bpr_detail_document_number");
			gsql.setValue(_bank_number 					,"bpr_detail_bank_number");
			//gsql.setValue(_create_date 					,"bpr_detail_create_date");
			//gsql.setValue(_create_time 					,"bpr_detail_create_time");
			//gsql.setAsDateTime(_emission_date			,"bpr_detail_emission_date");
			gsql.setAsDateTime(_expiration_date			,"bpr_detail_expiration_date");
			gsql.setAsDateTime(_payment_date			,"bpr_detail_payment_date");
			gsql.setAsDouble(_value 					,"bpr_detail_value");
			gsql.setAsDouble(_juros_value 				,"bpr_detail_juros_value");
			gsql.setAsDouble(_increment_value 			,"bpr_detail_increment_value");
			gsql.setAsDouble(_discount_value 			,"bpr_detail_discount_value");
			gsql.setAsDouble(_penalty_value 			,"bpr_detail_penalty_value");
			gsql.setAsDouble(_perc_juros 				,"bpr_detail_perc_juros");
			gsql.setAsDouble(_perc_discount 			,"bpr_detail_perc_discount");
			gsql.setAsDouble(_perc_penalty 				,"bpr_detail_perc_penalty");
			gsql.setValue(_penalty_after_days 			,"bpr_detail_penalty_after_days");
			gsql.setAsDateTime(_discount_until 			,"bpr_detail_discount_until");
			gsql.setValue(_check						,"bpr_detail_check");
			gsql.setValue(_ticket_printed 				,"bpr_detail_ticket_printed");
			gsql.setAsDateTime(_ticket_emission_date 		,"bpr_detail_ticket_emission_date");
			gsql.setValue(_historic 					,"bpr_detail_historic");
			gsql.setValue(_obs 							,"bpr_detail_obs");
			gsql.setValue(_bpr_id			 			,"bpr_detail_bpr_id");
			gsql.setValue(_status_id 					,"bpr_detail_status_id");
			gsql.setValue(_document_type_id 			,"bpr_detail_document_type_id");
			gsql.setValue(_user_id 						,"bpr_detail_user_id");
			gsql.setValue(_bank_id 						,"bpr_detail_bank_id");
			gsql.setValue(_agreement_id 				,"bpr_detail_agreement_id");
			gsql.setValue(_collection_type_id 			,"bpr_detail_collection_type_id");
			gsql.setValue(_check_id 					,"bpr_detail_check_id");
			gsql.setAsDouble(_paid_value           		,"bpr_detail_paid_value");  
		}	
	}
    
	public class BprDetails : common.DefaultList, common.IList
	{
		public BprDetails()
		{
			gsql.table = "finan.bpr_detail";
		}
		
		/*public List<BprDetail> items
		{
			get { return items; }
		}*/
		
		public BprDetail get(Int32 index)
		{
			return (BprDetail)items[index];
		}
		
		public BprDetail get()
		{
			return (BprDetail)items[index];
		}		
		
		public bool fillList()
		{
			gsql.prepare();
			gsql.setValue("","*");
			gsql.additionalWhere = "ORDER BY bpr_detail_number";
			
			return mountList();
		}
		
		public bool fillListByBprId(string bprId)
		{
			gsql.prepare();
			gsql.setValue("","*");
			gsql.conditionalWhere = "bpr_detail_bpr_id = "+bprId;
			gsql.additionalWhere = "ORDER BY bpr_detail_number";
			
			return mountList();
		}		
		
		private bool mountList()
		{
			Int32 tam;
			
			if (!gsql.execute())
				return false;
			
			tam = gsql.getRowCount();
			items.Clear();
			for (int i=0; i < tam; i++)
			{
				BprDetail aux = new BprDetail();
				aux.get(gsql.getRow(i));
				items.Add(aux);
			}
			return true;
		}
	}    	
}
